<?php
namespace app\admin\validate;

use think\Validate;

class Admin extends Validate
{
    protected $rule = [
       'username'=>'require|alphaNum|length:5,16|unique:admin',
       'password'=>'require|max:20',
       'code'   =>'require|captcha'
    ];
    protected $message = [
    	'username.require'=>'登陆名不能为空',
        'username.alphaNum'=>'登陆名只能为字母和数子',
        'username.length'=>'登陆名长度为5到16位',
        'username.unique'=>'该登陆名已存在',
        'password.require'=>'登陆密码不能为空',
        'password.max'=>'登陆密码过长',
        'code.require'=>'验证码不能为空',
        'code.captcha'=>'验证码不正确'
    ];
    public function sceneLogin()
    {
        return $this->only(['username','password','code'])
            ->remove('username', 'unique');
    }
    public function sceneAdd()
    {
        return $this->only(['username','password']);
    }
    public function sceneEdit()
    {
        return $this->only(['username','password'])
            ->remove('password', 'require');
    }
}
